package pkl51.model;

import java.io.Serializable;
import pkl51.entity.Blok5;
import pkl51.error.EntityException;
import pkl51.model.event.Blok5Listener;
import pkl51.service.Blok5Dao;
import pkl51.service.impl.Blok5DaoImpl;
/**
 *
 * @author ERI
 */
public class Blok5Model implements Serializable{
    private static Blok5Model instance;
    private static final long serialVersionUID = -4067881703503442209L;
    private String NKS ;
    private String B5R1a ; 
    private String B5R1b ;
    private String B5R1c ;
    private String B5R2ia ; 
    private String B5R2ib ;
    private String B5R2ic ;
    private String B5R2id ;
    private String B5R2iia ;
    private String B5R2iib ;
    private String B5R2iic ;
    private String B5R2iid ;
    private String B5R2iie ;
    private String B5R2iif ;
    private String B5R2iig ;
    private String B5R2iih ;
    private String B5R2iiia ;
    private String B5R2iiib ;
    private String B5R2iiic ;  
    private Blok5Listener listener;

    public void setForDB(String B5R1a, String B5R1b, String B5R1c, String B5R2ia, String B5R2ib, String B5R2ic, String B5R2id, String B5R2iia, String B5R2iib, String B5R2iic, String B5R2iid, String B5R2iie, String B5R2iif, String B5R2iig, String B5R2iih, String B5R2iiia, String B5R2iiib, String B5R2iiic) {
        
        this.B5R1a = B5R1a;
        this.B5R1b = B5R1b;
        this.B5R1c = B5R1c;
        this.B5R2ia = B5R2ia;
        this.B5R2ib = B5R2ib;
        this.B5R2ic = B5R2ic;
        this.B5R2id = B5R2id;
        this.B5R2iia = B5R2iia;
        this.B5R2iib = B5R2iib;
        this.B5R2iic = B5R2iic;
        this.B5R2iid = B5R2iid;
        this.B5R2iie = B5R2iie;
        this.B5R2iif = B5R2iif;
        this.B5R2iig = B5R2iig;
        this.B5R2iih = B5R2iih;
        this.B5R2iiia = B5R2iiia;
        this.B5R2iiib = B5R2iiib;
        this.B5R2iiic = B5R2iiic;
    }
    private Blok5Model() {
        this.NKS = Blok123Model.getInstance().getNKS();
    }  
    public static Blok5Model getInstance(){
        if(instance==null){
            instance = new Blok5Model();
        }
        return instance;
    }
    public void setListener(Blok5Listener listener) {
        this.listener = listener;
    }
    public String getB5R1a() {
        return B5R1a;
    }
    public void setB5R1a(String B5R1a) {
        this.B5R1a = B5R1a;
        fireOnChange(this);
    }

    public String getB5R1b() {
        return B5R1b;
    }

    public void setB5R1b(String B5R1b) {
        this.B5R1b = B5R1b;
        fireOnChange(this);
    }

    public String getB5R1c() {
        return B5R1c;
    }

    public void setB5R1c(String B5R1c) {
        this.B5R1c = B5R1c;
        fireOnChange(this);
    }

    public String getB5R2ia() {
        return B5R2ia;
    }

    public void setB5R2ia(String B5R2ia) {
        this.B5R2ia = B5R2ia;
        fireOnChange(this);
    }

    public String getB5R2ib() {
        return B5R2ib;
    }

    public void setB5R2ib(String B5R2ib) {
        this.B5R2ib = B5R2ib;
        fireOnChange(this);
    }

    public String getB5R2ic() {
        return B5R2ic;
    }

    public void setB5R2ic(String B5R2ic) {
        this.B5R2ic = B5R2ic;
        fireOnChange(this);
    }

    public String getB5R2id() {
        return B5R2id;
    }

    public void setB5R2id(String B5R2id) {
        this.B5R2id = B5R2id;
        fireOnChange(this);
    }
   
    public String getB5R2iia() {
        return B5R2iia;
    }

    public void setB5R2iia(String B5R2iia) {
        this.B5R2iia = B5R2iia;
        fireOnChange(this);
    }

    public String getB5R2iib() {
        return B5R2iib;
    }

    public void setB5R2iib(String B5R2iib) {
        this.B5R2iib = B5R2iib;
        fireOnChange(this);
    }

    public String getB5R2iic() {
        return B5R2iic;
    }

    public void setB5R2iic(String B5R2iic) {
        this.B5R2iic = B5R2iic;
        fireOnChange(this);
    }

    public String getB5R2iid() {
        return B5R2iid;
    }

    public void setB5R2iid(String B5R2iid) {
        this.B5R2iid = B5R2iid;
        fireOnChange(this);
    }

    public String getB5R2iie() {
        return B5R2iie;
    }

    public void setB5R2iie(String B5R2iie) {
        this.B5R2iie = B5R2iie;
        fireOnChange(this);
    }

    public String getB5R2iif() {
        return B5R2iif;
    }

    public void setB5R2iif(String B5R2iif) {
        this.B5R2iif = B5R2iif;
        fireOnChange(this);
    }

    public String getB5R2iig() {
        return B5R2iig;
    }

    public void setB5R2iig(String B5R2iig) {
        this.B5R2iig = B5R2iig;
        fireOnChange(this);
    }

    public String getB5R2iih() {
        return B5R2iih;
    }

    public void setB5R2iih(String B5R2iih) {
        this.B5R2iih = B5R2iih;
        fireOnChange(this);
    }

    public String getB5R2iiia() {
        return B5R2iiia;
    }

    public void setB5R2iiia(String B5R2iiia) {
        this.B5R2iiia = B5R2iiia;
        fireOnChange(this);
    }

    public String getB5R2iiib() {
        return B5R2iiib;
    }

    public void setB5R2iiib(String B5R2iiib) {
        this.B5R2iiib = B5R2iiib;
        fireOnChange(this);
    }

    public String getB5R2iiic() {
        return B5R2iiic;
    }

    public void setB5R2iiic(String B5R2iiic) {
        this.B5R2iiic = B5R2iiic;
        fireOnChange(this);
    }

    public String getNKS() {
        return NKS;
    }

    public void setNKS(String NKS) {
        this.NKS = NKS;
        fireOnChange(this);
    }

    

    protected void fireOnChange(Blok5Model model){
        if(listener!=null){
            listener.onChange(this);
        }
    }
    
    public void insertBlok5() throws EntityException{
        this.NKS = Blok123Model.getInstance().getNKS();
        Blok5Dao dao = new Blok5DaoImpl();
        Blok5 blok5= new Blok5();
        
        blok5.setNKS(NKS);
        blok5.setB5R1a(B5R1a);
        blok5.setB5R1b(B5R1b);
        blok5.setB5R1c(B5R1c);
        try {
            blok5.setB5R2ia(Integer.parseInt(B5R2ia));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2ia(null);
        }        
        try {
            blok5.setB5R2ib(Integer.parseInt(B5R2ib));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2ib(null);
        }
        try {
            blok5.setB5R2ic(Integer.parseInt(B5R2ic));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2ic(null);
        }
        try {
            blok5.setB5R2id(Integer.parseInt(B5R2id));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2id(null);
        }
        try {
            blok5.setB5R2iia(Integer.parseInt(B5R2iia));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iia(null);
        }
        try {
            blok5.setB5R2iib(Integer.parseInt(B5R2iib));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iib(null);
        }
        try {
            blok5.setB5R2iic(Integer.parseInt(B5R2iic));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iic(null);
        }
        try {
            blok5.setB5R2iid(Integer.parseInt(B5R2iid));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iid(null);
        }
        try {
            blok5.setB5R2iie(Integer.parseInt(B5R2iie));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iie(null);
        }
        try {
            blok5.setB5R2iif(Integer.parseInt(B5R2iif));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iif(null);
        }
        try {
            blok5.setB5R2iig(Integer.parseInt(B5R2iig));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iig(null);
        }
        try {
            blok5.setB5R2iih(Integer.parseInt(B5R2iih));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iih(null);
        }
        try {
            blok5.setB5R2iiia(Integer.parseInt(B5R2iiia));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iiia(null);
        }
        try {
            blok5.setB5R2iiib(Integer.parseInt(B5R2iiib));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iiib(null);
        }
        try {
            blok5.setB5R2iiic(Integer.parseInt(B5R2iiic));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iiic(null);
        }
       
        dao.insertBlok5(blok5);
    }
    public void updateBlok5() throws EntityException{
        this.NKS = Blok123Model.getInstance().getNKS();
        Blok5Dao dao = new Blok5DaoImpl();
        Blok5 blok5= new Blok5();
        
        blok5.setNKS(NKS);
        blok5.setB5R1a(B5R1a);
        blok5.setB5R1b(B5R1b);
        blok5.setB5R1c(B5R1c);
        try {
            blok5.setB5R2ia(Integer.parseInt(B5R2ia));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2ia(null);
        }        
        try {
            blok5.setB5R2ib(Integer.parseInt(B5R2ib));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2ib(null);
        }
        try {
            blok5.setB5R2ic(Integer.parseInt(B5R2ic));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2ic(null);
        }
        try {
            blok5.setB5R2id(Integer.parseInt(B5R2id));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2id(null);
        }
        try {
            blok5.setB5R2iia(Integer.parseInt(B5R2iia));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iia(null);
        }
        try {
            blok5.setB5R2iib(Integer.parseInt(B5R2iib));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iib(null);
        }
        try {
            blok5.setB5R2iic(Integer.parseInt(B5R2iic));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iic(null);
        }
        try {
            blok5.setB5R2iid(Integer.parseInt(B5R2iid));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iid(null);
        }
        try {
            blok5.setB5R2iie(Integer.parseInt(B5R2iie));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iie(null);
        }
        try {
            blok5.setB5R2iif(Integer.parseInt(B5R2iif));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iif(null);
        }
        try {
            blok5.setB5R2iig(Integer.parseInt(B5R2iig));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iig(null);
        }
        try {
            blok5.setB5R2iih(Integer.parseInt(B5R2iih));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iih(null);
        }
        try {
            blok5.setB5R2iiia(Integer.parseInt(B5R2iiia));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iiia(null);
        }
        try {
            blok5.setB5R2iiib(Integer.parseInt(B5R2iiib));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iiib(null);
        }
        try {
            blok5.setB5R2iiic(Integer.parseInt(B5R2iiic));
        } catch (NumberFormatException numberFormatException) {
            blok5.setB5R2iiic(null);
        }

        dao.updateBlok5(blok5);
    }
    public void getBlok5ByNks() throws EntityException{
        this.NKS = Blok123Model.getInstance().getNKS();
        Blok5Dao dao = new Blok5DaoImpl();
        Blok5 blok5 = dao.getBlok5ByNks(NKS);
        
        setNKS(blok5.getNKS());
        setB5R1a(blok5.getB5R1a());
        setB5R1b(blok5.getB5R1b());
        setB5R1c(blok5.getB5R1c());
        
        if(blok5.getB5R2ia()!=0)setB5R2ia(blok5.getB5R2ia().toString());
        else setB5R2ia("");
        
        if(blok5.getB5R2ib()!=0)setB5R2ib(blok5.getB5R2ib().toString());
        else setB5R2ib("");
        
        if(blok5.getB5R2ic()!=0)setB5R2ic(blok5.getB5R2ic().toString());
        else setB5R2ic("");
        
        if(blok5.getB5R2id()!=0)setB5R2id(blok5.getB5R2id().toString());
        else setB5R2id("");
        
        if(blok5.getB5R2iia()!=0)setB5R2iia(blok5.getB5R2iia().toString());
        else setB5R2iia("");
        
        if(blok5.getB5R2iib()!=0)setB5R2iib(blok5.getB5R2iib().toString());
        else setB5R2iib("");
        
        if(blok5.getB5R2iic()!=0)setB5R2iic(blok5.getB5R2iic().toString());
        else setB5R2iic("");
        
        if(blok5.getB5R2iid()!=0)setB5R2iid(blok5.getB5R2iid().toString());
        else setB5R2iid("");
        
        if(blok5.getB5R2iie()!=0)setB5R2iie(blok5.getB5R2iie().toString());
        else setB5R2iie("");
        
        if(blok5.getB5R2iif()!=0)setB5R2iif(blok5.getB5R2iif().toString());
        else setB5R2iif("");
        
        if(blok5.getB5R2iig()!=0)setB5R2iig(blok5.getB5R2iig().toString());
        else setB5R2iig("");
        
        if(blok5.getB5R2iih()!=0)setB5R2iih(blok5.getB5R2iih().toString());
        else setB5R2iih("");
        
        if(blok5.getB5R2iiia()!=0)setB5R2iiia(blok5.getB5R2iiia().toString());
        else setB5R2iiia("");
        
        if(blok5.getB5R2iiib()!=0)setB5R2iiib(blok5.getB5R2iiib().toString());
        else setB5R2iiib("");
        
        if(blok5.getB5R2iiic()!=0)setB5R2iiic(blok5.getB5R2iiic().toString());
        else setB5R2iiic("");
                     
        
    }
    
    public void resetModel(){
        setNKS("");
        setB5R1a("");
        setB5R1b("");
        setB5R1c("");
        setB5R2ia("");
        setB5R2ib("");
        setB5R2ic("");
        setB5R2id("");
        setB5R2iia("");
        setB5R2iib("");
        setB5R2iic("");
        setB5R2iid("");
        setB5R2iie("");
        setB5R2iif("");
        setB5R2iig("");
        setB5R2iih("");
        setB5R2iiia("");
        setB5R2iiib("");
        setB5R2iiic("");
    }
}
